package com.newspublish.system.controller;

import com.newspublish.system.entity.system.Category;
import com.newspublish.system.service.CategoryService;
import com.newspublish.system.utils.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags="分类管理")
@RestController
@RequestMapping("/admin/news/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation(value="添加分类")
    @PostMapping("/addCategory")
    public Result addCategory(Category category){
        return categoryService.addCategory(category);
    }

    @ApiOperation(value="删除分类")
    @DeleteMapping("/deleteCategory/{id}")
    public Result deleteCategory(@PathVariable("id") Long id){
        return categoryService.deleteCategory(id);
    }

    @ApiOperation(value="根据id获取分类信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id") Long id){
        return categoryService.getByPrimaryKey(id);
    }

    @ApiOperation(value="获取所有分类")
    @GetMapping("/getAllCategory")
    public Result getAllCategory(){
        return categoryService.getAllCategory();
    }

    @ApiOperation(value="修改分类")
    @PutMapping("/updateCategory")
    public Result updateCategory(Category category){
        return categoryService.updateCategory(category);
    }

}
